package com.bbc.service.type.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bbc.base.page.MysqlPaginatedArrayList;
import com.bbc.base.page.PaginatedList;
import com.bbc.entity.type.BbcType;
import com.bbc.entity.type.BbcTypeQuery;
import com.bbc.mapper.type.BbcTypeMapper;
import com.bbc.service.type.BbcTypeService;

@Service
public class BbcTypeServiceImpl implements BbcTypeService {
	
	@Autowired
	private transient BbcTypeMapper bbcTypeMapper;

	@Override
	public Integer addBbcType(BbcType bbcType) {
		return bbcTypeMapper.addBbcType(bbcType);
	}

	@Override
	public BbcType findBbcTypeById(Integer typeId) {
		return bbcTypeMapper.findBbcTypeById(typeId);
	}

	@Override
	public List<BbcType> findBbcType(BbcTypeQuery query) {
		return bbcTypeMapper.findBbcType(query);
	}

	@Override
	public List<BbcType> findBbcType(BbcTypeQuery query, int page, int pageSize) {
		PaginatedList<BbcType> list = new MysqlPaginatedArrayList<BbcType>(page,pageSize);
		list.setTotalItem(bbcTypeMapper.findBbcTypeCount(query));
		query.setStartRow(list.getStartRow());
		query.setEndRow(list.getEndRow());
		list.addAll(bbcTypeMapper.findBbcType(query));
		return list;
	}

	@Override
	public int findBbcTypeCount(BbcTypeQuery query) {
		return bbcTypeMapper.findBbcTypeCount(query);
	}

	@Override
	public void updateBbcType(BbcType bbcType) {
		bbcTypeMapper.updateBbcType(bbcType);
	}

	@Override
	public List<BbcType> findBbcType(Integer level) {
		BbcTypeQuery query = new BbcTypeQuery();
		query.setLevel(level);
		return bbcTypeMapper.findBbcType(query);
	}

	@Override
	public List<BbcType> findBbcTypeByParent(Integer parentId) {
		BbcTypeQuery query = new BbcTypeQuery();
		query.setParentId(parentId);
		return bbcTypeMapper.findBbcType(query);
	}

}
